package com.lu.pojo.lambda;

/**
 * @author luzhenfang
 * @date 2020 05 23
 * @description lambda 表达式
 * 函数式接口：只包含一个抽象方法的接口
 * lambda前提：函数式接口
 *  推导：函数式接口 -> 实现类 -> 静态内部类 -> 局部内部类 ->匿名内部类 ->lambda
 */


// 函数式接口
interface ILike {
    void lambda();
}


class Like implements ILike {

    @Override
    public void lambda() {
        System.out.println("I like Lambda!");
    }
}


class TestLambda {
    static class Like2 implements ILike {

        @Override
        public void lambda() {
            System.out.println("I like Lambda!(inner static)");
        }
    }

    // 静态内部类
    public static void main(String[] args) {
        ILike like = new Like();
        like.lambda();

        Like2 like2 = new Like2();

        like2.lambda();

        // 局部内部类
        class Like3 implements ILike {

            @Override
            public void lambda() {
                System.out.println("I like Lambda!(temp)");
            }
        }

        Like3 like3 = new Like3();
        like3.lambda();

        // 匿名内部类 (没有类名称 必须借助接口或者父类）
        ILike iLike = new ILike() {
            @Override
            public void lambda() {
                System.out.println("I like Lambda!(anonymous)");

            }
        };
        iLike.lambda();
        // finally lambda
       ILike likeLambda=()->{
            System.out.println("I like Lambda!(lambda)");
        };
        likeLambda.lambda();
    }
}